var SystemFunctions = new Class({
	initialize: function(mysql){
		this.builds = {};
		this.mysql = mysql;
		this.parseAllFunctions();
	}
	,addNewGroup: functions(gname){
		if(!this.functions[gname]) throw "Grupo existente";
		this.builds[gname] = {};
	}
	,addFunctionsToGroup: function(gname, functions){
		this.addNewGroup(gname);
		this.builds[gname] = {
			checkParams : functions.checkParams
			,checkBuildPosibility: functions.checkBuildPosibility
			,build: functions.build
			,notBuild: functions.notBuild
		}
	}
	
	//Parse all defs for import functions.
	,parseAllFunctions: function(){
	var q = "";
		this.mysql.query(q, function(err, results, fields){
			if(err){
				console.log("No se puede parsear mysql para obtener el nombre de los edificios.");
				throw err;
			}
			for(res in results){
				this.addFunctionsToGroup(res, require(res+'.js') );
			}
		}.bind(this));
	}
	,getAllFunctions: function(){
		return {
			builds: this.builds
		};
	}
});

exports.getAllFunctions = function(mysql){
	var systemFunctions = new SystemFunctions(mysql);
	return systemFunctions.getAllFunctions();
}
